import axios from 'axios'

export default {
  namespaced: true,
  state: {
    categoryList: [],
    currentCategory: ''
  },
  mutations: {
    updateCategoryList (state, payload) {
      state.categoryList = payload
    },
    updateCurrentCategory (state, payload) {
      state.currentCategory = payload
    }
  },
  actions: {
    async getCategoryList ({ commit }) {
      const { data: { data: { channels } } } = await axios.get('http://toutiao.itheima.net/v1_0/channels')

      commit('updateCategoryList', channels)
      commit('updateCurrentCategory', channels[0].id)
    }
  }
}
